//延时加载
$.getScript("/js/jquery.lazyload.mini.js");
/*
id 你要滚动的内容的id
l 横坐标的位置 不写为紧贴右边
t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边
f 1表示固定 不写或者0表示滚动
*/
function scrollx(p){
	var d = document,
	dd = d.documentElement,
	db = d.body,
	w = window,
	o = d.getElementById(p.id),
	ie6 = /msie 6/i.test(navigator.userAgent),style,timer;
	
	if(o){
		o.style.cssText +=";position:"+(p.f&&!ie6?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
		if(p.f&&ie6){
			o.style.cssText +=';left:expression(documentElement.scrollLeft + '+(p.l==undefined?dd.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(documentElement.scrollTop +'+(p.t==undefined?dd.clientHeight-o.offsetHeight:p.t)+'+ "px" );';
			dd.style.cssText +=';background-image: url(about:blank);background-attachment:fixed;';
		}else{
			if(!p.f){
				w.onresize = w.onscroll = function(){
					clearInterval(timer);
					timer = setInterval(function(){
						//双选择为了修复chrome 下xhtml解析时dd.scrollTop为 0
						var st = (dd.scrollTop||db.scrollTop),c;
						c = st - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||dd.clientHeight)-o.offsetHeight);
						if(c!=0){
							o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px';
						}else{
							clearInterval(timer);
						}
					},10)
				}
			}
		}
	}
}
//scrollx({id:'float',l:-30,f:1,t:floatDiv_h});
//选择分类
//ESC关闭
function chooseClass() {
	overlay();
	$("#chooseClass").show();
	
	$("#overlay").click(function(){ $("#chooseClass").hide();  });
	var l	=	($(window).width()-$("#chooseClass").width())/2;
	var t	=	($(window).height()-$("#chooseClass").height())/2;
	scrollx({id:'chooseClass',f:1,l:l,t:t});
	
	$(".b li").mouseover(function(){
		var cid	= $(this).attr("cid");
		$(".s li").hide();
		$(".s_"+cid).show();
	})
	$(".s li").click(function(){
		var cid	= $(this).attr("cid");
		var htm = $(this).html();
		$("#classid").val(cid);
		$(".cc").val(htm);
		$("#overlay").click();
	})
	$(window).keydown(function(event){
	  if(event.keyCode==27)
	  {
		  $("#overlay").click();
	  }
	});
}


//阴影遮罩层
//已带点击关闭事件
function overlay(){
	var overlay = document.createElement("div");
	overlay.id = "overlay";

	overlay.style.background="#999999";
	overlay.style.opacity = "0.5";
	overlay.style.display="none";
	overlay.style.position="absolute";
	overlay.style.top="0px";
	overlay.style.left="0px";
	
	overlay.style.width=$(window).width()+"px";
	overlay.style.height=$(window).height()+"px";
	overlay.style.cursor="pointer";
	overlay.style.cursor="hand";
	//overlay.style.zIndex = 100;
	
	document.body.appendChild(overlay);
	
	scrollx({id:'overlay',f:1});
	
	$("#overlay").fadeIn();
	
	overlay.onclick	= function(){
		$("#overlay").fadeOut();
		setTimeout(function(){$("#overlay").remove()},1000);
	}
}


//图片上传
function settings(){
    var api = 'http://www.365inf.com';
    var settings = {
		flash_url : api+"/images/swfupload.swf",
        upload_url : api+"/app/?m=image&a=upload",

        file_size_limit : "1 MB",
        file_types : "*.gif;*.jpg;*jpeg;*.png;*.bmp",
        file_types_description : "图片",
        file_upload_limit : 1,
        debug: false,
        button_width: "65",
        button_height: "29",
        button_placeholder_id: "upload",
        button_text: '上传图片',
        button_text_style: ".theFont { font-size: 16; }",
        button_text_left_padding: 12,
        button_text_top_padding: 13,
        file_queued_handler : queued,//关闭对话框时触发 
        file_queue_error_handler : fileQueueError,//选择的文件加入到上传队列中失败时触发
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler : queueComplete// Queue plugin event 
    };
    return settings;
}
function fileQueueError(obj,errorcode,message){
	alert(1);
    if(SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED)alert("图片数量超过限制")
    if(SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT)alert("图片大小超过限制")
    if(SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE)alert("请选择图片")
    if(SWFUpload.QUEUE_ERROR.INVALID_FILETYPE)alert("请选择正确图片类型")
}

function uploadStart(file){
	$("#uploading").fadeIn();
    $("#uploadDia").html(file.name+" 正在上传/文件大小："+file.size+" 字节/请稍候...");
}
function uploadProgress(file,bytescomplete,totalbytes){
	$("#uploadDia").html(file.name+" 已完成："+bytescomplete+'/'+file.size);
}
function uploadError(file,code,message){
    if(code==240) alert("图片大小超过限制");
    if(code==250) alert("上传失败");
    this.cancelUpload(file.id);
    ////idHTTP_ERROR : -200,
    ////200MISSING_UPLOAD_URL : -210,
    ////210IO_ERROR : -220,
    ////220SECURITY_ERROR : -230,
    ////230UPLOAD_LIMIT_EXCEEDED : -240,
    ////240UPLOAD_FAILED : -250,
    ////250SPECIFIED_FILE_ID_NOT_FOUND : -260,
    ////260FILE_VALIDATION_FAILED : -270,
    ////270FILE_CANCELLED : -280,
    ////280UPLOAD_STOPPED : -290 
    //290
}
//上传正确
function uploadSuccess(file,data){
	$("#uploading").fadeOut();
	$("#uploadDia").html("");
	$("#piclist").append("<li><img src='"+data+"' /></li>");
	alert(data)
}
//上传完成
function uploadComplete(){
}
    //
function queueComplete(){
    //
    //queueComplete
    //
}
   //
function fileDialogComplete(selected,queuednum){
    if(queuednum<4){
        this.startUpload();
    }
}

//关闭对话框时触发 
function queued(event){
}


function scrollX(){
	var de = document.documentElement;
	
	return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}

function scrollY(){
	var de = document.documentElement;
	
	return self.pageYOffset || (de  && de.scrollTop) || document.body.scrollTop;
}

function windowHeight(){
	var de = document.documentElement;
	return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}

function windowWidth(){
	var de = document.documentElement;
	return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
}


function mouseLocation(ev){
	ev = ev || window.event;
	var mousePos = mousePosition(ev);
	return mousePos;
} 
function mousePosition(ev){
    if(ev.pageX || ev.pageY){
          return {x:ev.pageX, y:ev.pageY};
    }
    return {
          x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
          y:ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
function getScreenSize(){
	var w = 0;
	var h = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		w = window.innerWidth;
		h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return {width:w,height:h};
}

//加入收藏
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    } catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        } catch (e) {
            alert("加入收藏失败,请手动添加.");
        }
    }
}
//设为首页
function setHomepage(pageURL) {
    if (document.all) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(pageURL);
    }
    else if (window.sidebar) {
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项signed.applets.codebase_principal_support 值该为true" );
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage',pageURL);
    }
}
